<?php
require_once "includes/config.php";
require_once "includes/functions.php";

$sqlExpireClassified="select * from tbl_post where expire_status='No'";
$exeExpireClassified=mysql_query($sqlExpireClassified) or die(mysql_error());
while($arrExpireClassified=mysql_fetch_array($exeExpireClassified))
{
   $today=time();
   $post_date=strtotime($arrExpireClassified['posted_date']);
   $expire_date=strtotime($arrExpireClassified['posted_date'])+($arrExpireClassified['post_duration']*24*60*60);
   if($today>$expire_date)
   {
	 $subject="Your Post Ad Expired";
	 $sqlEmail="select * from tbl_emails where email_type='Classified Expired'";
	 $resEmail=mysql_query($sqlEmail);
	 $rowEmail=mysql_fetch_array($resEmail);
	 
	 $selCategory=mysql_fetch_array(mysql_query("select * from tbl_category where category_id='".$arrExpireClassified['category_id']."'"));
	 
	 $selUser=mysql_fetch_array(mysql_query("select * from tbl_users where user_id='".$arrExpireClassified['posted_by']."'"));
	 $fullname=$selUser['first_name']." ".$selUser['last_name'];
	 
	 $message=str_replace('%fname%',$selUser['first_name'],str_replace('%lname%',$selUser['last_name'],str_replace('%post_classified%',stripslashes($arrExpireClassified['post_name']),str_replace('%classidied_category%',stripslashes($selCategory['category_name']),$rowEmail['email_body']))));
	 $headers = "From: Swapen.com<mail@swapen.com> \r\n";
	 $headers .= 'MIME-Version: 1.0' . "\r\n";
	 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	 mail($selUser['email'],$subject, $message, $headers);
	 
	 mysql_query("update tbl_post set expire_status='Yes' where post_id='".$arrExpireClassified['post_id']."'") or die(mysql_error());
   }
}
?>

